<template>
    <div class="ebook">
        <ebook-title></ebook-title>
        <ebook-reader></ebook-reader>
        <ebook-menu></ebook-menu>
    </div>
</template>

<script>
import EbookReader from '@/components/ebook/EbookReader' 
import EbookMenu from '@/components/ebook/EbookMenu'
import EbookTitle from '@/components/ebook/EbookTitle'
import { ebookMixin } from '../../utils/mixin'
import { getReadTime,saveReadTime } from '../../utils/localStorage'
export default {
    mixins: [ebookMixin],
    components: { 
        EbookReader,
        EbookMenu,
        EbookTitle
    },
    data() {
        return {
            
        };
    },

    mounted() {
        
    },

    methods: {
        startLoopReadTime() { //循环计算阅读时间
            let readTime = getReadTime(this.fileName)
            if(!readTime) { 
                readTime = 0
            }
            this.task = setInterval(() => { 
                readTime++ //每隔一秒readtime加一
                if(readTime % 30 === 0) { //每隔30秒保存到本地一次
                    saveReadTime(this.fileName,readTime)
                }
            },1000)
        }
    },
    mounted() { 
        this.startLoopReadTime() //开启定时器
    },
    beforeDestroy() {
        clearInterval(this.task)  //关闭定时器
    },
    
};
</script>

<style lang="scss" scoped>

</style>